#include "Bullet.h"
#include <sstream>
#include <GL/glut.h>

using namespace std;

// Constructor
Bullet::Bullet(){
	Object3D::Object3D("");
	fMaxHeight = 25.0f;
	rBoundingBox = new Rectangle(0.0f,0.0f,0.6f,1.4f);
}
Bullet::Bullet(std::string strTexturePath){
	Object3D::Object3D(strTexturePath);
	fMaxHeight = 25.0f;
	rBoundingBox = new Rectangle(0.0f,0.0f,0.6f,1.4f);
}

// Main Functions
void Bullet::Initialize(Vec3f* vOrigin){
	vTranslation = vOrigin;	
}
bool Bullet::Update(float deltaTime){
	vTranslation->v[1] += 30.33f*deltaTime/1000*iDirection;
	rBoundingBox->SetX(vTranslation->v[0]);
	rBoundingBox->SetY(vTranslation->v[1]);
	if (vTranslation->v[1]>fMaxHeight || vTranslation->v[1]<-1*fMaxHeight)
		return false;
	return true;
}
void Bullet::Draw(){
	glTranslatef(vTranslation->v[0],vTranslation->v[1],0.0f);	
	glScalef(vScale->v[0], vScale->v[1], vScale->v[2]); //Scale 
	glRotatef(vRotation->v[0], 1.0f, 0.0f, 0.0f); //Rotate about the x-axis
	glRotatef(vRotation->v[1], 0.0f, 1.0f, 0.0f); //Rotate about the y-axis
	glRotatef(vRotation->v[2], 0.0f, 0.0f, 1.0f); //Rotate about the z-axis
	glBegin(GL_QUADS);
	
	//Trapezoid
	glColor3f(1.0f, 0.1f, 0.1f);
	glVertex3f(-0.3f, -0.7f, 0.0f);
	glVertex3f(0.3f, -0.7f, 0.0f);
	glColor3f(0.0f, 0.0f, 0.0f);
	glVertex3f(0.3f, 0.7f, 0.0f);
	glVertex3f(-0.3f, 0.7f, 0.0f);
	
	glEnd();
	glPopMatrix(); //Undo the move
	glPushMatrix(); //Save the current state 
}

// Setters and Getters
void Bullet::SetDirection(int iDirection){
	this->iDirection = iDirection;
}
int Bullet::GetDirection(){
	return iDirection;
}